-- CALC_MONSTER_DODGE
-- 计算怪物闪避

return function(monster)
    local dodge = monster.dbase:query("dodge", 0);

    local combine = PropM.combine;
    local apply = PropM.apply;
    local fetchProps = PropM.fetchProps;
    local trigger = PropM.trigger;

    -- 1. 百分比加成
    local propId = PropM.getPropId("attrib");
    local prop = combine(monster, propId, "dodge");
    dodge = apply(prop, dodge);

    -- 2. 绝对值加成
    propId = PropM.getPropId("attrib2");
    prop = combine(monster, propId, "dodge");
    dodge = apply(prop, dodge);

    -- 每阵亡一个同类，闪避+N
    local props = fetchProps(monster, "violent2");
    for _, p in ipairs(props) do
        if p[2] == "dodge" then
            dodge = trigger(monster, p[1], p[2], dodge);
        end
    end

    -- 生命低于50%增加闪避
    props = fetchProps(monster, "hp_to_dodge");
    for _, prop in ipairs(props) do
        dodge = trigger(monster, prop[1], prop[2], dodge);
    end

    -- 3. 被削弱
    prop = combine(monster, "reduce_attrib", "dodge");
    dodge = apply(prop, dodge);

    -- 4. 被削弱
    prop = combine(monster, "reduce_attrib2", "dodge");
    dodge = apply(prop, dodge);

    -- 玩家的忽视闪避属性
    prop = combine(ME.user, "ignore_dodge", 1);
    dodge = apply(prop, dodge);

    -- 开板数量降低闪避100%
    props = fetchProps(monster, "open_grids_reduce");
    for _, p in ipairs(props) do
        if p[2] == "dodge" then
            dodge = trigger(monster, p[1], p[2], dodge);
        end
    end

    -- 被变成青蛙/骷髅，闪避清零
    prop = combine(monster, "transfiguration", 1);
    if prop[3] > 0 then
        dodge = 0;
    end
    prop = combine(monster, "skeleton", 1);
    if prop[3] > 0 then
        dodge = 0;
    end

    return dodge;
end
